﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class LoaiPhongDAO
    {
        public static DataTable GetAll()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select * From LoaiPhong";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable LayLoaiPhong()
        {
            DataProvider dp = new DataProvider();
            string sql = "Select TenLoaiPhong, MaLoaiPhong From LoaiPhong";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable LoaiPhongTheoTen(string ten)
        {
            DataProvider dp = new DataProvider();
            string sql = "Select * From LoaiPhong Where TenLoaiPhong = '" + ten + "'";
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static DataTable LoaiPhongTheoMaPhong(int maphong)
        {
            DataProvider dp = new DataProvider();
            string sql = string.Format("Select l.TenLoaiPhong From Phong p, LoaiPhong l Where l.MaLoaiPhong=p.MaLoaiPhong and p.MaPhong = " + maphong + "");
            DataTable dt = dp.ExecuteQuery(sql);
            return dt;
        }

        public static void ThemLoaiPhong(LoaiPhongDTO lp)
        {
            string sql = string.Format("INSERT INTO LoaiPhong(MaLoaiPhong, TenLoaiPhong, SoKhachToiDa, DonGia) VALUES (" + lp.MaLoaiPhong + ",'" + lp.TenLoaiPhong + "'," + lp.SoKhachToiDa + "," + lp.DonGia + ")");
            DataProvider.ExecuteNonQuery(sql);
        }

        public static void CapNhatLoaiPhong(LoaiPhongDTO lp)
        {
            string sql = string.Format("Update LoaiPhong Set TenLoaiPhong = '" + lp.TenLoaiPhong + "', SoKhachToiDa = " + lp.SoKhachToiDa + ", DonGia=" + lp.DonGia + " Where MaLoaiPhong = " + lp.MaLoaiPhong + "");
            DataProvider.ExecuteNonQuery(sql);
        }

        public static void XoaLoaiPhong(int maphong)
        {
            string sql = string.Format("Delete From LoaiPhong Where MaLoaiPhong = " + maphong + "");
            DataProvider.ExecuteNonQuery(sql);
        }
    }
}
